#include <gtest/gtest.h>

#include <algorithm>
#include <random>
#include <string>
#include <vector>

using namespace std;

struct TempSt {
    int    id;
    string name;
};

TEST(Test_find, DefaultUsage) {
    vector<int> v{1, 3, 5, 7, 9};

    auto iter = find(v.begin(), v.end(), 5);

    EXPECT_EQ(iter, v.begin() + 2);
    EXPECT_EQ(*iter, 5);
}

TEST(Test_find_if, DefaultUsage) {
    vector<TempSt> v{
        {1, "a"},
        {2, "b"},
        {3, "c"},
        {4, "d"},
        {5, "e"}
    };

    auto iter = find_if(v.begin(), v.end(), [](const TempSt& t) { return t.id == 3; });

    EXPECT_EQ(iter, v.begin() + 2);
    EXPECT_EQ(iter->id, 3);
    EXPECT_EQ(iter->name, "c");
}

TEST(Test_min_element, DefaultUsage) {
    vector<int> v(10);

    mt19937 rng(random_device{}());

    uniform_int_distribution<int> dist(0, 1024);
    generate_n(v.begin(), 10, [&]() { return dist(rng); });

    auto iter  = min_element(v.begin(), v.end());
    auto value = *iter;

    sort(v.begin(), v.end());

    EXPECT_EQ(value, v[0]);
}
